package com.whmskj.xjlhsc.mobie.Scheduling.controller;

import com.whmskj.xjlhbc.core.AjaxResult;
import com.whmskj.xjlhbc.core.Page;
import com.whmskj.xjlhsc.mobie.Scheduling.Service.LeaveRequestService;
import com.whmskj.xjlhsc.mobie.Scheduling.entity.LeaveRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Sakura
 * @Date: 2025/9/2 11:05
 * @Version: v1.0.0
 * @Description: TODO
 **/
@RestController
@RequestMapping("/mob/leave")
@Api(tags = "请假管理")
public class LeaveRequestController {

    @Autowired
    private LeaveRequestService leaveRequestService;

    @PostMapping("/listByCondition")
    @ApiOperation("获取请假列表（分页）")
    public AjaxResult getLeavePageByCondition(@RequestBody LeaveRequest condition) {
        Page.startPage();
        List<LeaveRequest> list = leaveRequestService.getLeaveListByCondition(condition);
        return Page.getDataTable(list);
    }

    @PostMapping("/add")
    @ApiOperation("新增请假")
    public AjaxResult addLeave(@RequestBody LeaveRequest leaveRequest) {
            boolean result = leaveRequestService.addLeaveRequest(leaveRequest);
            return result ? AjaxResult.success("新增成功") : AjaxResult.error("新增失败");
    }

    @PutMapping("/update")
    @ApiOperation("更新请假")
    public AjaxResult updateLeave(@RequestBody LeaveRequest leaveRequest) {
        boolean result = leaveRequestService.updateLeaveRequest(leaveRequest);
        return result ? AjaxResult.success("更新成功") : AjaxResult.error("更新失败");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除请假")
    public AjaxResult deleteLeave(@PathVariable Long id) {
            boolean result = leaveRequestService.deleteLeaveRequest(id);
            return result ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }
}
